package cn.wolfcode.controller;

import cn.wolfcode.domain.Spot;
import cn.wolfcode.service.ISpotService;
import cn.wolfcode.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spot")
public class SpotController {
    @Autowired
    private ISpotService spotService;

    @RequestMapping("/list")
    public Object list(){
        List<Spot> list = spotService.findAll();
        return JsonResult.success(list);
    }


    @RequestMapping("/saveOrUpdate")
    public Object saveOrUpdate(Spot spot){


        if(spot.getId() == null){
            spotService.save(spot);
        }else{
            spotService.update(spot);
        }
        return JsonResult.success();
    }


    @RequestMapping("/de")
    public Object de(String id){

        Spot spot = spotService.get(id);

        return  JsonResult.success(spot);
    }



}
